home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Mathematics / Notebooks / URichMultivariateCalculus / 10 / Lab10.ma next >
Encoding:
Text File  |  1991-12-03  |  14.1 KB  |  228 lines

  1. (*^
  2.  
  3. ::[paletteColors = 128; currentKernel; 
  4.     fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e8,  24, "Times"; ;
  5.     fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, L1, e6,  18, "Times"; ;
  6.     fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, L1, e6,  14, "Times"; ;
  7.     fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, L1, a20,  18, "Times"; ;
  8.     fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, L1, a15,  14, "Times"; ;
  9.     fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, L1, a12,  12, "Times"; ;
  10.     fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  11.     fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  10, "Times"; ;
  12.     fontset = input, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L1,  12, "Courier"; ;
  13.     fontset = output, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5,  12, "Courier"; ;
  14.     fontset = message, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  15.     fontset = print, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  16.     fontset = info, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L1,  12, "Courier"; ;
  17.     fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, L1,  12, "Courier"; ;
  18.     fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, L1,  10, "Times"; ;
  19.     fontset = header, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  20.     fontset = Left Header, nohscroll, cellOutline,  12;
  21.     fontset = footer, inactive, nohscroll, noKeepOnOnePage, preserveAspect, center, M7, L1,  12;
  22.     fontset = Left Footer, cellOutline, blackBox,  12;
  23.     fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  10, "Times"; ;
  24.     fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  25.     fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12, "Courier"; ;
  26.     fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  27.     fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  28.     fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  29.     fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;
  30.     fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, L1,  12;]
  31. :[font = title; inactive; Cclosed; preserveAspect; startGroup; ]
  32. Lab 10:  Vector Calculus
  33. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  34. Two-Dimensional Vector Fields
  35. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  36. This new version of Mathematica includes a package for plotting vector fields.  The following command loads the package for two-dimensional vector fields:
  37. ;[s]
  38. 3:0,0;20,1;31,2;154,-1;
  39. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  40. :[font = input; preserveAspect; endGroup; ]
  41. <<Graphics/PlotField.m
  42. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  43. Example
  44. :[font = text; inactive; preserveAspect; ]
  45. Here is a fairly simple two-dimensional vector field:
  46. :[font = input; preserveAspect; ]
  47. F[x_,y_] := { y, x }
  48. :[font = text; inactive; preserveAspect; ]
  49. This, of course, means: F(x,y) = y i + x j .
  50. :[font = text; inactive; preserveAspect; ]
  51. If we interpret F[x,y] to be the wind velocity at the point {x,y}, then this says that the velocity at the point {1,-2} is {-2,1}.
  52. :[font = text; inactive; preserveAspect; ]
  53. The PlotVectorField command shows what it looks like:
  54. :[font = input; preserveAspect; ]
  55. PlotVectorField[ F[x,y], {x,-2,2}, {y,-2,2} ];
  56. :[font = text; inactive; preserveAspect; endGroup; ]
  57. To locate the vector at the point {1,-2}, select the graph (click on it), and then drag the mouse cursor across it while holding down the Command key.  The coordinates of the cursor will be displayed at the bottom right corner of the window.  Move the cursor until these coordinates are {1,-2.001}.  At that location on the plot you should see a little arrow whose direction is {-2,1}.
  58. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  59. Exercises
  60. :[font = text; inactive; preserveAspect; ]
  61. For each of the following, draw the vector field over the domain specified, and then use the Command-drag technique to check the vector at the point (1,-2):
  62. :[font = text; inactive; preserveAspect; ]
  63. 1.  F[x_,y_] := { -y, x }  over  -2 <= x <= 2  and  -2 <= y <= 2 .
  64. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  65. 2.  F[x_,y_] := { y / Sqrt[x^2+y^2], x / Sqrt[x^2+y^2] }  over  -2 <= x <= 2  
  66.      and  -2 <= y <= 2 .
  67. :[font = section; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  68. Gradient Fields and Hamiltonian Fields
  69. :[font = text; inactive; preserveAspect; ]
  70. The gradient of a scalar field is a vector field.  It is called the gradient field of the scalar field, and the scalar field is called a potential function for the vector field.
  71. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  72. Example
  73. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  74. Here is a simple scalar field:
  75. :[font = input; preserveAspect; ]
  76. f[x_,y_] := x^2 + y^2
  77. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  78. and this is its gradient vector field:
  79. :[font = input; preserveAspect; endGroup; ]
  80. F[x_,y_] = { D[f[x,y],x], D[f[x,y],y] }
  81. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  82. Here's a plot of this gradient field:
  83. :[font = input; preserveAspect; endGroup; endGroup; ]
  84. PlotVectorField[ F[x,y], {x,-2,2}, {y,-2,2} ];
  85. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  86. The PlotGradientField command (in the same PlotField package) plots the gradient field F of a given potential funtion f directly, thereby obviating the need to find F first:
  87. :[font = input; preserveAspect; endGroup; ]
  88. PlotGradientField[ f[x,y], {x,-2,2}, {y,-2,2} ]
  89. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  90. The PlotHamiltonianField command (also in the PlotField package) plots the Hamiltonian field H of a given potential funtion f:
  91. :[font = input; preserveAspect; endGroup; endGroup; ]
  92. PlotHamiltonianField[ f[x,y], {x,-2,2}, {y,-2,2} ]
  93. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  94. Exercises
  95. :[font = text; inactive; preserveAspect; ]
  96. Plot both the Gradient field and the Hamiltonian field for each of the following potential functions.  Then explain how the two are related:
  97. :[font = text; inactive; preserveAspect; ]
  98. 1.  f[x_,y_] := x^2 - y^2  over  -2 <= x <= 2  and  -2 <= y <= 2 .
  99. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  100. 2.  f[x_,y_] := Sin[x] Cos[y]  over  -Pi <= x <= 2Pi  and  -Pi <= y <= Pi .
  101. :[font = section; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  102. Streamlines
  103. :[font = text; inactive; preserveAspect; ]
  104. Recall that the gradient vector always points in the direction of maximum increase of a function.  Therefore the gradient will always be perpendicular to the function's level curves because they consist of all points where the function has the same value.
  105. :[font = text; inactive; preserveAspect; ]
  106. This new version of Mathematica allows the user to specify which level curves are to be drawn by the ContourPlot command.  This allows us to see more clearly the relationships between a function's gradient field, its Hamiltonian field, and its level curves.
  107. ;[s]
  108. 3:0,0;20,1;31,2;257,-1;
  109. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  110. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  111. Example
  112. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  113. Here's the same example we used above:
  114. :[font = input; preserveAspect; ]
  115. f[x_,y_] := x^2 + y^2
  116. :[font = input; preserveAspect; endGroup; ]
  117. Plot3D[ f[x,y], {x,-2,2}, {y,-2,2} ];
  118. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  119. Here again are its gradient and Hamiltonian fields:
  120. :[font = input; preserveAspect; ]
  121. gf = PlotGradientField[ f[x,y], {x,-2,2}, {y,-2,2} ];
  122. :[font = input; preserveAspect; endGroup; ]
  123. hf = PlotHamiltonianField[ f[x,y], {x,-2,2}, {y,-2,2} ];
  124. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  125. And here they are together:
  126. :[font = input; preserveAspect; ]
  127. Show[ {gf,hf} ];
  128. :[font = text; inactive; preserveAspect; endGroup; ]
  129. From this picture, we can clearly see that the two fields are orthogonal—that is, their vectors are perpendicular.
  130. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  131. Now let's look at the level curve for f at the level z = 4:
  132. :[font = input; preserveAspect; ]
  133. cf = ContourPlot[ f[x,y], {x,-2,2}, {y,-2,2},
  134.     ContourShading -> False, ContourSmoothing -> Automatic,
  135.     Contours -> {4} ]
  136. :[font = text; inactive; preserveAspect; ]
  137. Since the level curve is perpendicular to the gradient field at each point, it must be parallel to the Hamiltonian field at each point.  This means that the level curve will be a streamline for the Hamiltonian vector field:
  138. :[font = input; preserveAspect; ]
  139. Show[ {hf,cf} ];
  140. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  141. If this vector field represents the wind's velocity vectors, then the curve will be the path of a particle controlled by that force.
  142. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  143. Exercises
  144. :[font = text; inactive; preserveAspect; ]
  145. Use the ContourPlot command, as shown above, to draw the level curve at the given z-value.  Then show the curve on the same picture with the function's Hamiltonian field.  Use the output numbers of the plots that you did in the previous section.  For example, if the first exercise was Out[23], then input:  Show[ { %23, cf } ]
  146. :[font = text; inactive; preserveAspect; ]
  147. 1.  f[x_,y_] := x^2 - y^2  over  -2 <= x <= 2  and  -2 <= y <= 2 , at z = 1.
  148. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  149. 2.  f[x_,y_] := Sin[x] Cos[y]  over  -Pi <= x <= 2Pi  and  -Pi <= y <= Pi , at z = 0.5
  150. :[font = section; inactive; Cclosed; preserveAspect; startGroup; ]
  151. Three-Dimensional Vector Fields
  152. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  153. The new version of Mathematica can also plot three-dimensional vector fields.  Those commands are in the following package:
  154. ;[s]
  155. 3:0,0;19,1;30,2;123,-1;
  156. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  157. :[font = input; preserveAspect; endGroup; ]
  158. <<Graphics/PlotField3D.m
  159. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  160. Example
  161. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  162. Here's Example 4 from page 809:
  163. :[font = input; preserveAspect; ]
  164. F[x_,y_,z_] := { x y z, x^2, -x y }
  165. :[font = input; preserveAspect; endGroup; ]
  166. PlotVectorField3D[ F[x,y,z], {x,-2,2}, {y,-2,2}, {z,-2,2} ];
  167. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  168. The package also includes a three-dimensional PlotGradientField command.  Here's a plot of the gradient field of the potential function  f (x,y,z) = xyz:
  169. :[font = input; preserveAspect; endGroup; endGroup; ]
  170. PlotGradientField3D[ x y z, {x,-1,1}, {y,-1,1}, {z,-1,1} ];
  171. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  172. Exercises
  173. :[font = text; inactive; preserveAspect; ]
  174. 1.  Plot the vector field defined in Exercise 4 on page 810.
  175. :[font = text; inactive; preserveAspect; endGroup; endGroup; ]
  176. 2.  Plot the vector field defined in Exercise 3 on page 831.
  177. :[font = section; inactive; Cclosed; pageBreak; preserveAspect; startGroup; ]
  178. Vector Derivative Operators
  179. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  180. The next external package that we need has some conflicts with the previous packages that we have already loaded.  Consequently, you will have to quit the current kernel before loading the new package.  Give the Quit/Disconnect Kernel… command (in the Action>Kernels submenu), and click on the Yes button to quit the kernel.  Then load this package:
  181. :[font = input; preserveAspect; ]
  182. <<Calculus/VectorAnalysis.m
  183.  
  184. :[font = text; inactive; preserveAspect; endGroup; ]
  185. It contains all the usual vector derivative opeators: Grad, Div, Curl, and Laplacian.
  186. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  187. Example
  188. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  189. Here's Example 2 from page 807:
  190. :[font = input; preserveAspect; ]
  191. F[x_,y_,z_] := { 5x^2 y, x y, x^2 z }
  192. :[font = input; preserveAspect; ]
  193. F[x,y,z]
  194. :[font = input; preserveAspect; ]
  195. Div[ F[x,y,z] ]
  196. :[font = input; preserveAspect; endGroup; ]
  197. Curl[ F[x,y,z] ]
  198. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  199. Here's the definition of the gradient of a three-dimensional scalar field:
  200. :[font = input; preserveAspect; endGroup; ]
  201. Grad[ f[x,y,z] ]
  202. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  203. And here's Mathematica's proof of the identity in Exercise 11 on page 810:
  204. ;[s]
  205. 3:0,0;11,1;22,2;74,-1;
  206. 3:1,11,8,Times,0,12,0,0,0;1,10,8,Times,2,12,0,0,0;1,11,8,Times,0,12,0,0,0;
  207. :[font = input; preserveAspect; endGroup; endGroup; ]
  208. Curl[ Grad[ f[x,y,z] ] ]
  209. :[font = subsection; inactive; Cclosed; preserveAspect; startGroup; ]
  210. Exercises
  211. :[font = text; inactive; preserveAspect; ]
  212. 1.  Exercise 1 on page 810.
  213. :[font = text; inactive; preserveAspect; ]
  214. 2.  Exercise 7 on page 810.
  215. :[font = text; inactive; Cclosed; preserveAspect; startGroup; ]
  216. 3.  Exercise 21 on page 811.   Hint: define:
  217. :[font = input; preserveAspect; ]
  218. F[x_,y_,z_] := { P[x,y,z], Q[x,y,z], R[x,y,z] };
  219. G[x_,y_,z_] := { S[x,y,z], T[x,y,z], U[x,y,z] };
  220. :[font = text; inactive; preserveAspect; ]
  221. and then compare:
  222. :[font = input; preserveAspect; ]
  223. Div[ CrossProduct[ F[x,y,z], G[x,y,z] ] ]
  224. :[font = text; inactive; preserveAspect; ]
  225. with:
  226. :[font = input; preserveAspect; endGroup; endGroup; endGroup; endGroup; ]
  227. G[x,y,z].Curl[F[x,y,z]] - F[x,y,z].Curl[G[x,y,z]]
  228. ^*)